package kr.hkit.powerjava.chapter22.work2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

import kr.hkit.powerjava.chapter22.work2.dao.StudentManagerImpl;
import kr.hkit.powerjava.chapter22.work2.vo.Student;

public class TestMain {
	public static void main(String[] args) {
		ArrayList<Student> stdList = new ArrayList<>();
		StudentManagerImpl sm = new StudentManagerImpl(stdList);
		
		//추가
		Student std1 = new Student(1, "김태희", 90, 90, 90);
		sm.addItem(std1);
		Student std2 = new Student(2, "제시카", 89, 79, 77);
		sm.addItem(std2);
		sm.addItem(new Student(3, "김주하", 80, 80, 80));
		sm.addItem(new Student(4, "이민정", 78, 79, 89));
		sm.addItem(std1);
		//삭제
/*		sm.delItem(std1);
		sm.delItem(std2);*/

		//검색
		Student searchItem = new Student(1, "제시카");
		String result = sm.searchItem(searchItem)?"존재":"없음";
		System.out.println(searchItem.getStdNum() + ":" + searchItem.getStdName() + " = " + result);

		//수정
		Student updateItem = new Student(1, "김태희", 91, 93, 94);
		sm.updateItem(updateItem);
		//출력
		sm.prnItems();
		System.out.println("총점순 정렬(내림차순)");
		sm.prnItems(new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return (int) (o2.getTotal()-o1.getTotal());
			}
		});
		
		System.out.println("이름순 정렬(오름차순)");
		sm.prnItems(new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return o1.getStdName().hashCode()-o2.getStdName().hashCode();
			}
		});
		
		System.out.println("국어점수 정렬(내림차순)");
		sm.prnItems(new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return o2.getKor()-o1.getKor();
			}
		});
		
		
		for(Student std : stdList){
			System.out.println(std);
		}
		
		Collections.shuffle(stdList);
		System.out.println("반복자================");
		Student std = null;
		Iterator<Student> iterator = stdList.iterator();
		while(iterator.hasNext()){
			std = iterator.next();
			System.out.println(std);
		}
	}
}







